package com.egao.common.manage.school;

import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.credits.entity.Credits;
import com.egao.common.module.credits.service.CreditsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author lym
 * @date 2022/1/21 9:45
 */
@Api(tags = "项目学分管理")
@RestController
@RequestMapping("${api}")
public class SchoolCreditsController extends BaseController {

    @Autowired
    private CreditsService creditsService;

    @PreAuthorize("hasAuthority('school:credits:list')")
    @ApiOperation("分页查询")
    @OperLog(value = "项目学分管理", desc = "分页查询")
    @GetMapping("/school/credits/page")
    public PageResult<Credits> page(HttpServletRequest request) {
        PageParam<Credits> pageParam = new PageParam<>(request);
        return new PageResult<>(creditsService.listPage(pageParam), pageParam.getTotal());
    }

    @PreAuthorize("hasAuthority('school:credits:list')")
    @ApiOperation("删除项目学分")
    @OperLog(value = "项目学分管理", desc = "删除项目学分", result = true)
    @DeleteMapping("/school/credits/delete")
    public JsonResult delete(Integer id) {
        if (creditsService.removeById(id)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }
}
